package main

import (
	"fmt"
	"sync"
)
var wg sync.WaitGroup
func main() {

	ch1 := make(chan int)
	ch2 := make(chan int)
	wg.Add(2)
	go pump1(ch1)
	go pump2(ch2)
	go suck(ch1, ch2)
	//等待任务执行完成
	wg.Wait()

}

func pump1(ch chan int) {
	for i := 0; i<10; i++ {
		ch <- i
	}
	wg.Done()
}

func pump2(ch chan int) {
	for i := 0; i<10; i++ {
		ch <- i
	}
	wg.Done()
}

func suck(ch1, ch2 chan int) {
	for {
		select {
		case v := <-ch1:
			fmt.Printf("Received on channel 1: %d\n", v)
		case v := <-ch2:
			fmt.Printf("Received on channel 2: %d\n", v)
		}
	}
}